package com.clkj.cldisabledmanclient.adapter.jaylv;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

public abstract class JayLvBaseAdapter<T> extends BaseAdapter {
	protected LayoutInflater mInflater;
	protected Context mContext;
	protected List<T> mDatas;
    protected final int mItemLayoutId;  

	public JayLvBaseAdapter(Context context, List<T> datas, int itemLayoutId){
		mInflater = LayoutInflater.from(context);
		this.mContext = context;
		this.mDatas = datas;
		this.mItemLayoutId = itemLayoutId;
	}
	
	@Override
	public int getCount() {
		return mDatas.size();
	}

	@Override
	public T getItem(int position) {
		return mDatas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent)
    {  
        final ViewHolder viewHolder = getViewHolder(position, convertView,  
                parent);  
        convert(viewHolder,position, getItem(position));

        return viewHolder.getConvertView();  
    }  
	
	private ViewHolder getViewHolder(int position, View convertView,
            ViewGroup parent)   {
		return ViewHolder.get(mContext
				, convertView, parent, mItemLayoutId, position);
	}
	
	public abstract void convert(ViewHolder helper,int position, T item);

}
